 package tp.pr5.mv.window;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import tp.pr5.mv.CPU;
import tp.pr5.mv.Controller;
import tp.pr5.mv.Instruction;
import tp.pr5.mv.Memory;
import tp.pr5.mv.OperandStack;
import tp.pr5.mv.ProgramCounter;
import tp.pr5.mv.ProgramMV;

@SuppressWarnings("serial")
public class PanelPop extends JPanel implements CPU.Observer {

	/* Panel con un boton pop que permite desapilar elementos de la pila de la CPU
	 * */
	private JButton pop;
	
	public PanelPop( Controller controller) {
		
		super( new FlowLayout() );
		init( controller);
		
	}
	
	public void init(final Controller controller) {
		
		pop = new JButton("Pop");
		pop.addActionListener( new ActionListener() { // Cuando se pulsa el boton se desapila un elemento y se repinta la pila de la ventana 

			@Override
			public void actionPerformed(ActionEvent arg0) {
				controller.requestPop();
			}
			
			
			
		});
		add(pop);
		
	}

	@Override
	public void onStartInstrExecution(Instruction ins) {}

	@Override
	public void onEndInstrExecution(Instruction instr, Memory mem,
			OperandStack stack, ProgramCounter pc) {}

	@Override
	public void onHalt() {}

	@Override
	public void onReset(ProgramMV program) {}

	@Override
	public void onStartRun() { // Desactiva el botón de pop
		pop.setEnabled(false);
		
	}

	@Override
	public void onEndRun(boolean aborted) {
		pop.setEnabled(true);
	}

	@Override
	public void onTrap(Instruction instr, String trapMessage) {}


}
